package net.citrite.android;


import com.android.SdkConstants;

import java.io.File;
import java.util.logging.Logger;

public class Project {
    private static final Logger logger = Logger.getLogger(Project.class.getName());
    private ManifestParser manifestParser;
    private File resLocation;
    public static Project createFromManifest(File manifestFile) throws Exception {
        logger.severe(String.format("Start parse %s", manifestFile.getCanonicalPath()));
        if (manifestFile == null) {
            throw new NullPointerException("AndroidManifest.xml does not exist");
        }
        if (!manifestFile.exists() || !manifestFile.getName().equals("AndroidManifest.xml")) {
            throw new IllegalArgumentException("AndroidManifest.xml");
        }
        Project project = new Project();
        project.resLocation = new File(manifestFile.getParent(), SdkConstants.FD_RESOURCES);
        File layoutFolder = new File(project.resLocation, SdkConstants.FD_RES_LAYOUT);
        File valuesFolder = new File(project.resLocation, SdkConstants.FD_RES_VALUES);
        if (!layoutFolder.isDirectory() || !valuesFolder.isDirectory()) {
            throw new IllegalArgumentException("project is invalid");
        }
        project.manifestParser = new ManifestParser(manifestFile);
        return project;
    }

    public File getResLocation() {
        return resLocation;
    }

    public String getTheme(String activityName) {
        return manifestParser.getActivityTheme(activityName);
    }
}
